package zhongbo.javaweb.instagram.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import zhongbo.javaweb.instagram.dto.JsonRespDto;
import zhongbo.javaweb.instagram.schedule.HeartBeatCheckSchedule;

/**
 * 说明：
 *
 * @author zhongboWork
 * @version 1.0
 * @since 2022-01-06 19:05
 */
@RequestMapping("/middle")
@Controller
@Slf4j
@Api(value = "中间件相关接口", tags = {"中间件相关接口"})
public class MiddleController {

    @Autowired
    private HeartBeatCheckSchedule heartBeatCheckSchedule;

    @ResponseBody
    @RequestMapping(value = "/lastHeart", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询上次心跳时间接口")
    public JsonRespDto<Long> last() {
        long last = heartBeatCheckSchedule.getLastHeartbeat();
        return new JsonRespDto<Long>().setData(last).makeSuccess();
    }

    @ResponseBody
    @RequestMapping(value = "/ping", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "http心跳接口")
    public JsonRespDto<Long> ping() {
        heartBeatCheckSchedule.heartBeat();
        return new JsonRespDto<Long>().makeSuccess();
    }


}
